package com.zheng.service.impl;

import com.zheng.entity.User;
import com.zheng.mapper.UserMapper;
import com.zheng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public List<User> list() {
        return userMapper.selectList();
    }

    @Override
    public String redisTestAdd() {
        Integer count = 1;
        count++;
        stringRedisTemplate.opsForValue().set("1","123"+count);

        return null;
    }

    @Override
    public String redisTestExpir() {
        System.out.printf("123");
//        stringRedisTemplate.expire("1",30, TimeUnit.SECONDS);
        redisTemplate.opsForValue().set("2","222",30,TimeUnit.SECONDS);
//        stringRedisTemplate.opsForValue().set("2","222",30,TimeUnit.SECONDS);
        System.out.printf("成功");
        return null;
    }
}
